<form name="form_order" id="form_order" method="post">	
	<article class="module width_full">
		<header><h3 class="tabs_involved">DANH SÁCH ĐƠN ĐẶT HÀNG</h3>
		<ul class="tabs">
   			<li><a href="#tab1">Tất cả</a></li>
    		<li><a href="#tab2">Đơn đặt hàng</a></li>
			<li><a href="#tab3">Đang sẵn sàng</a></li>
			<li><a href="#tab4">Đã giao</a></li><br>

			<link rel="stylesheet" type="text/css" href="<?php echo base_url()."public/admin/css/jquery.datetimepicker.css";?>"/>
			<br>
			<center>
			<input type="text" id="datetimepicker"/><br>
			<button class='submit' type='submit'>Cập nhật</button>
			</center>
			<script src="<?php echo base_url()."public/admin/js/jquery.js";?>"></script>
			<script type="text/javascript" src="<?php echo base_url()."public/admin/js/jquery.datetimepicker.js";?>"></script>
			<script>
			var $j110 = jQuery.noConflict(true);
			$j110('#datetimepicker').datetimepicker({inline:true,});
			</script>
		</ul>
		</header>
		<div class="tab_container"  style="overflow-y:scroll; height:300px">
			<div id="tab1" class="tab_content">
			<table class="tablesorter" cellspacing="0" > 
			<thead> 
				<tr> 
   					<th></th> 
    				<th>Mã số</th> 
    				<th>Ngày đặt</th> 
    				<th>Trạng thái</th> 
    				<th>Hành động</th> 
				</tr> 
			</thead> 
			<tbody> 
			<?php
				foreach($all as $value)
				{
					echo "<tr id='tr".$value->so_hoadon."' name='tr".$value->so_hoadon."'>";
   					echo "<td><input name='check_hoadon' id='".$value->so_hoadon."' type='checkbox'></td>";
    				echo '<td>'.$value->so_hoadon.'</td>'; 
    				echo '<td>'.$value->ngay_dat_hang.'</td>'; 
    				echo '<td>';
					echo "<select id='status_order_".$value->so_hoadon."' nam='status_order_".$value->so_hoadon."' required='true' style='width: 150px;'>";
					if($value->ngay_dat_hang<>'0000-00-00 00:00:00' && $value->ngay_donggoi_ss=='0000-00-00 00:00:00' && $value->ngay_giaohang_thanhcong=='0000-00-00 00:00:00') 
					{
						echo "<option value='0' selected>Đặt hàng mới</option>";
						echo "<option value='1'>Đã sẵn sàng</option>";
						echo "<option value='2' disabled>Đã giao</option>";					
					}
					if($value->ngay_dat_hang<>'0000-00-00 00:00:00' && $value->ngay_donggoi_ss<>'0000-00-00 00:00:00' && $value->ngay_giaohang_thanhcong=='0000-00-00 00:00:00')
					{
						echo "<option value='0' disabled>Đặt hàng mới</option>";
						echo "<option value='1' selected>Đã sẵn sàng</option>";
						echo "<option value='2'>Đã giao</option>";							
					}	
					if($value->ngay_dat_hang<>'0000-00-00 00:00:00' && $value->ngay_donggoi_ss<>'0000-00-00 00:00:00' && $value->ngay_giaohang_thanhcong<>'0000-00-00 00:00:00')
					{
						echo "<option value='0' disabled>Đặt hàng mới</option>";
						echo "<option value='1' disabled>Đã sẵn sàng</option>";
						echo "<option value='2' selected>Đã giao</option>";							
					}					
					echo "</select>";				
					echo "</td>";
    				echo "<td><a class='view-order' href='".$value->so_hoadon."'><input type='image' src='".base_url()."public/admin/images/icn_categories.png' title='Xem chi tiết đơn hàng'></a>
					<a class='delete-order' href='".$value->so_hoadon."'><input type='image' src='".base_url()."public/admin/images/icn_trash.png'title='Xóa đơn hàng'></a>";		
					echo '</tr>'; 
				}
			?>
			</tbody> 
			</table>
			</div><!-- end of #tab1 -->
			
			<div id="tab2" class="tab_content">
			<table class="tablesorter" cellspacing="0" > 
			<thead> 
				<tr> 
   					<th></th> 
    				<th>Mã số</th> 
    				<th>Ngày đặt</th> 
    				<th>Trạng thái</th> 
    				<th>Hành động</th> 
				</tr> 
			</thead> 
			<tbody> 
			<?php
				foreach($dathang as $value)
				{
					echo "<tr id='tr".$value->so_hoadon."' name='tr".$value->so_hoadon."'>";
   					echo "<td><input name='check_hoadon' id='".$value->so_hoadon."' type='checkbox'></td>";
    				echo '<td>'.$value->so_hoadon.'</td>'; 
    				echo '<td>'.$value->ngay_dat_hang.'</td>'; 
    				echo '<td>';
					echo "<select id='status_order_".$value->so_hoadon."' nam='status_order_".$value->so_hoadon."' required='true' style='width: 150px;'>";
					if($value->ngay_dat_hang<>'0000-00-00 00:00:00' && $value->ngay_donggoi_ss=='0000-00-00 00:00:00' && $value->ngay_giaohang_thanhcong=='0000-00-00 00:00:00') 
					{
						echo "<option value='0' selected>Đặt hàng mới</option>";
						echo "<option value='1'>Đã sẵn sàng</option>";
						echo "<option value='2' disabled>Đã giao</option>";					
					}
					if($value->ngay_dat_hang<>'0000-00-00 00:00:00' && $value->ngay_donggoi_ss<>'0000-00-00 00:00:00' && $value->ngay_giaohang_thanhcong=='0000-00-00 00:00:00')
					{
						echo "<option value='0' disabled>Đặt hàng mới</option>";
						echo "<option value='1' selected>Đã sẵn sàng</option>";
						echo "<option value='2'>Đã giao</option>";							
					}	
					if($value->ngay_dat_hang<>'0000-00-00 00:00:00' && $value->ngay_donggoi_ss<>'0000-00-00 00:00:00' && $value->ngay_giaohang_thanhcong<>'0000-00-00 00:00:00')
					{
						echo "<option value='0' disabled>Đặt hàng mới</option>";
						echo "<option value='1' disabled>Đã sẵn sàng</option>";
						echo "<option value='2' selected>Đã giao</option>";							
					}					
					echo "</select>";				
					echo "</td>";
    				echo "<td><a class='view-order' href='".$value->so_hoadon."'><input type='image' src='".base_url()."public/admin/images/icn_categories.png' title='Xem chi tiết đơn hàng'></a>
					<a class='delete-order' href='".$value->so_hoadon."'><input type='image' src='".base_url()."public/admin/images/icn_trash.png'title='Xóa đơn hàng'></a>";			
					echo '</tr>'; 
				}
			?>
			</tbody> 
			</table>
			</div><!-- end of #tab1 -->
			<div id="tab3" class="tab_content">
			<table class="tablesorter" cellspacing="0" > 
			<thead> 
				<tr> 
   					<th></th> 
    				<th>Mã số</th> 
    				<th>Ngày đóng gói</th> 
    				<th>Trạng thái</th> 
    				<th>Hành động</th> 
				</tr> 
			</thead> 
			<tbody> 
			<?php
				foreach($sansang as $value)
				{
					echo "<tr id='tr".$value->so_hoadon."' name='tr".$value->so_hoadon."'>";
   					echo "<td><input name='check_hoadon' id='".$value->so_hoadon."' type='checkbox'></td>";
    				echo '<td>'.$value->so_hoadon.'</td>'; 
    				echo '<td>'.$value->ngay_dat_hang.'</td>'; 
    				echo '<td>';
					echo "<select id='status_order_".$value->so_hoadon."' nam='status_order_".$value->so_hoadon."' required='true' style='width: 150px;'>";
					if($value->ngay_dat_hang<>'0000-00-00 00:00:00' && $value->ngay_donggoi_ss=='0000-00-00 00:00:00' && $value->ngay_giaohang_thanhcong=='0000-00-00 00:00:00') 
					{
						echo "<option value='0' selected>Đặt hàng mới</option>";
						echo "<option value='1'>Đã sẵn sàng</option>";
						echo "<option value='2' disabled>Đã giao</option>";					
					}
					if($value->ngay_dat_hang<>'0000-00-00 00:00:00' && $value->ngay_donggoi_ss<>'0000-00-00 00:00:00' && $value->ngay_giaohang_thanhcong=='0000-00-00 00:00:00')
					{
						echo "<option value='0' disabled>Đặt hàng mới</option>";
						echo "<option value='1' selected>Đã sẵn sàng</option>";
						echo "<option value='2'>Đã giao</option>";							
					}	
					if($value->ngay_dat_hang<>'0000-00-00 00:00:00' && $value->ngay_donggoi_ss<>'0000-00-00 00:00:00' && $value->ngay_giaohang_thanhcong<>'0000-00-00 00:00:00')
					{
						echo "<option value='0' disabled>Đặt hàng mới</option>";
						echo "<option value='1' disabled>Đã sẵn sàng</option>";
						echo "<option value='2' selected>Đã giao</option>";							
					}					
					echo "</select>";				
					echo "</td>";
    				echo "<td><a class='view-order' href='".$value->so_hoadon."'><input type='image' src='".base_url()."public/admin/images/icn_categories.png' title='Xem chi tiết đơn hàng'></a>
					<a class='delete-order' href='".$value->so_hoadon."'><input type='image' src='".base_url()."public/admin/images/icn_trash.png'title='Xóa đơn hàng'></a>";			
					echo '</tr>'; 
				}
			?>
			</tbody> 
			</table>
			</div><!-- end of #tab1 -->
			
			<div id="tab4" class="tab_content">
			<table class="tablesorter" cellspacing="0" > 
			<thead> 
				<tr> 
   					<th></th> 
    				<th>Mã số</th> 
    				<th>Ngày giao</th> 
    				<th>Trạng thái</th> 
    				<th>Hành động</th> 
				</tr> 
			</thead> 
			<tbody> 
			<?php
				foreach($dagiao as $value)
				{
					echo "<tr id='tr".$value->so_hoadon."' name='tr".$value->so_hoadon."'>";
   					echo "<td><input name='check_hoadon' id='".$value->so_hoadon."' type='checkbox'></td>";
    				echo '<td>'.$value->so_hoadon.'</td>'; 
    				echo '<td>'.$value->ngay_dat_hang.'</td>'; 
    				echo '<td>';
					echo "<select id='status_order_".$value->so_hoadon."' nam='status_order_".$value->so_hoadon."' required='true' style='width: 150px;'>";
					if($value->ngay_dat_hang<>'0000-00-00 00:00:00' && $value->ngay_donggoi_ss=='0000-00-00 00:00:00' && $value->ngay_giaohang_thanhcong=='0000-00-00 00:00:00') 
					{
						echo "<option value='0' selected>Đặt hàng mới</option>";
						echo "<option value='1'>Đã sẵn sàng</option>";
						echo "<option value='2' disabled>Đã giao</option>";					
					}
					if($value->ngay_dat_hang<>'0000-00-00 00:00:00' && $value->ngay_donggoi_ss<>'0000-00-00 00:00:00' && $value->ngay_giaohang_thanhcong=='0000-00-00 00:00:00')
					{
						echo "<option value='0' disabled>Đặt hàng mới</option>";
						echo "<option value='1' selected>Đã sẵn sàng</option>";
						echo "<option value='2'>Đã giao</option>";							
					}	
					if($value->ngay_dat_hang<>'0000-00-00 00:00:00' && $value->ngay_donggoi_ss<>'0000-00-00 00:00:00' && $value->ngay_giaohang_thanhcong<>'0000-00-00 00:00:00')
					{
						echo "<option value='0' disabled>Đặt hàng mới</option>";
						echo "<option value='1' disabled>Đã sẵn sàng</option>";
						echo "<option value='2' selected>Đã giao</option>";							
					}					
					echo "</select>";				
					echo "</td>";
    				echo "<td><a class='view-order' href='".$value->so_hoadon."'><input type='image' src='".base_url()."public/admin/images/icn_categories.png' title='Xem chi tiết đơn hàng'></a>
					<a class='delete-order' href='".$value->so_hoadon."'><input type='image' src='".base_url()."public/admin/images/icn_trash.png'title='Xóa đơn hàng'></a>";			
					echo '</tr>'; 
				}
			?>
			</tbody> 
			</table>
			</div><!-- end of #tab1 -->					
			
		</div><!-- end of .tab_container -->
		
	</article><!-- end of content manager article -->	
</form>
<article class="module width_full" style="display:none;">
<form id="view_order" class="contact_form" method="post" name="contact_form">
</form>
</article>

<form id="delete_order" class="contact_form" method="post" name="contact_form">
</form>
<script>
	$(document).ready(function() {
	   $('#form_order').submit(function(e){
			e.preventDefault();
			var count=0;
			$('input[name="check_hoadon"]').each(function() { 
				if(this.checked) { 
					count+=1;
					var id_checker=$(this).attr("id");
					var selector = "#status_order_"+id_checker;
					var status_order=$(selector).val();
					var date_update=$('#datetimepicker').val();
					if(date_update=='')
					{
						alert('Bạn chưa chọn ngày giờ cập nhật trạng thái!');
					}
					else
					{
						$.ajax({
							type: "POST",
							url: globalurl+'index.php/admin/update_order',
							data: {
								so_hoadon: id_checker,
								status_order: status_order,
								date_update: date_update
							},
							success: function(data) {	
								alert('Cập nhật thành công!');
								location.reload();
							}
						});					
					}

				}
			});
			if(count==0) alert('Chưa chọn đơn hàng để cập nhật!');
		});
		
	   $('.view-order').click(function(e) {
			e.preventDefault();	
			var so_hoadon=$(this).attr("href");
				$.ajax({
					type: "POST",
					url: globalurl+'index.php/admin/view_order',
					data: {
						id_details: so_hoadon
					},
					success: function(data) {
						$(".module").show();
						$('#view_order').html(data);	
						$('#view_order').toggle("slow");					
						
					}
				});  
			
			
		});	

	   $('.delete-order').click(function(e) {
			e.preventDefault();
			var id_order=$(this).attr("href");
			if (confirm('Bạn có muốn xóa đơn hàng này?')){
				$.ajax({
					type: "POST",
					url: globalurl+'index.php/admin/deleteorder',
					data: {
						id_order: id_order              
					},
					success: function(data) {
						$('#tr'+id_order).hide();
					}
				});  
			}			
			
		});		
	});
</script>
	

